package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import modelo.ConsultasExterna;
import modelo.tabla.JTableModelConsultasExternas;
import persistencia.BaseDatosConsultasExternas;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author dam2b
 */
public class JpConsultasExternas extends javax.swing.JPanel {

    ArrayList<ConsultasExterna> alCEX;
    Vector<String> vColumnNames;
    JTable jt;
    JTableModelConsultasExternas tmm;
    BaseDatosConsultasExternas db;

    /**
     * Creates new form JpConsultasExternas
     */
    public JpConsultasExternas() {
        initComponents();
        this.activarRadioB();
//        jScrollPane1.add(jt);
    }

    public void crearTabla() throws ClassNotFoundException/* SQLException*/ {
        /* alCEX = gmo.verModelo();
         alMo = gmo.getModelos();*/
        alCEX = new ArrayList();
        vColumnNames.addElement("ID CE");
        vColumnNames.addElement("ID PACIENTE");
        vColumnNames.addElement("FECHA");
        vColumnNames.addElement("HORA ENTRADA");
        vColumnNames.addElement("HORA SALIDA");
        vColumnNames.addElement("ESPECIALIDAD");

        tmm = new JTableModelConsultasExternas(vColumnNames, alCEX);
        jt = new JTable(tmm);
        jScrollPane1.setViewportView(jt);
    }

    public void activarRadioB() {

        ButtonGroup jbG = new ButtonGroup();
        jbG.add(JRBHE);
        jbG.add(JRBESPE);
        jbG.add(JRBHS);
        jbG.add(JRBIDPa);
        jbG.add(jRBFecha);

        JRBESPE.isSelected();

        jRBFecha.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                jTextField5.setEnabled(true);
                jButton2.setEnabled(true);

            }
        });

        JRBESPE.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                jTextField5.setEnabled(true);
                jButton2.setEnabled(true);

            }
        });
        JRBHS.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                jTextField5.setEnabled(true);
                jButton2.setEnabled(true);

            }
        });
        JRBIDPa.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                jTextField5.setEnabled(true);
                jButton2.setEnabled(true);

            }
        });

    }

    public void modificarDatosTabla() throws ClassNotFoundException, SQLException {
        /* String nombre = jTextField1.getText();
         String Emisiones = Float.parseFloat(jTextField3.getText());
         String Consumo = Float.parseFloat(jTextField2.getText());
         String */
        int id_modelo;
        id_modelo = (int) jt.getValueAt(jt.getSelectedRow(), 0);
        db.getCe1(id_modelo);
        db.updateCE(null, WIDTH);
        
        
    }

    public void borrarElemento() {

        int id_modelo;
        id_modelo = (int) jt.getValueAt(jt.getSelectedRow(), 0);
        try {
            db.deleteCE(id_modelo);
            JOptionPane.showMessageDialog(null, "Borrado completado con exito");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Borrado completado con exito");
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jToolBar1 = new javax.swing.JToolBar();
        jBBuscar = new javax.swing.JButton();
        jBModificar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jButton2 = new javax.swing.JButton();
        jRBFecha = new javax.swing.JRadioButton();
        JRBIDPa = new javax.swing.JRadioButton();
        JRBHE = new javax.swing.JRadioButton();
        JRBHS = new javax.swing.JRadioButton();
        JRBESPE = new javax.swing.JRadioButton();

        setPreferredSize(new java.awt.Dimension(800, 600));
        setRequestFocusEnabled(false);

        jToolBar1.setRollover(true);

        jBBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/search.png"))); // NOI18N
        jBBuscar.setFocusable(false);
        jBBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jBBuscar);

        jBModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/modificar.png"))); // NOI18N
        jToolBar1.add(jBModificar);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/borrar.png"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jLabel3.setFont(new java.awt.Font("Verdana", 2, 24)); // NOI18N
        jLabel3.setText("CONSULTAR CEX");

        jTextField5.setEnabled(false);

        jPanel1.setLayout(new java.awt.BorderLayout());
        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jButton2.setText("Buscar");
        jButton2.setEnabled(false);

        jRBFecha.setText("Fecha");

        JRBIDPa.setText("Id Paciente");

        JRBHE.setText("Hora de Entrada");

        JRBHS.setText("Hora de Subida");

        JRBESPE.setText("Especialidad");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(203, 203, 203)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jRBFecha)
                                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(JRBHS)
                                                .addComponent(JRBESPE)
                                                .addGroup(layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(JRBIDPa)
                                                                .addComponent(JRBHE))
                                                        .addGap(32, 32, 32)
                                                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(27, 27, 27)
                                                        .addComponent(jButton2)))
                                        .addGap(0, 198, Short.MAX_VALUE)))
                        .addContainerGap())
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addGap(39, 39, 39)
                        .addComponent(jRBFecha)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(5, 5, 5)
                                        .addComponent(JRBIDPa)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(JRBHE))
                                .addGroup(layout.createSequentialGroup()
                                        .addGap(19, 19, 19)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jButton2))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(JRBHS)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(JRBESPE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton JRBESPE;
    private javax.swing.JRadioButton JRBHE;
    private javax.swing.JRadioButton JRBHS;
    private javax.swing.JRadioButton JRBIDPa;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jBBuscar;
    private javax.swing.JButton jBModificar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRBFecha;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
